<?php
class Recruitment extends Controller{
	//Global variable
    public $outputData; //Holds the output data for each view
    public $loggedInUser;

    function __construct(){
    	parent::__construct();
        $this->load->model("recruitment_model");
        $this->load->helper('users');

        $this->load->model('common_model');
        $this->load->model('skills_model');
        $this->load->model('user_model');
        $this->load->model('transaction_model');
        $this->load->model('settings_model');
        $this->load->model('file_model');

        $this->load->model('messages_model');



        $this->loggedInUser = $this->common_model->getLoggedInUser();
        $this->outputData['loggedInUser'] = $this->loggedInUser;
        $this->config->db_config_fetch();

        $this->outputData = $this->common_model->getPageTitleAndMetaData();
        // load languge
        $this->lang->load('enduser/common', $this->config->item('language_code'));

    	//Get Config Details From Db

        //Manage site Status
        if ($this->config->item('site_status') == 1)
            redirect('offline');
    }


    function showSingleRecruitment($job_id = "",$industry_id=""){
        $this->load->helper('users');
        if(filter_var($job_id, FILTER_VALIDATE_INT, array('min_range' =>1)) && filter_var($industry_id, FILTER_VALIDATE_INT, array('min_range' =>1))){
            // nếu $job_id là integer
            if($job_id != '' && $industry_id !=''){
                // nếu $job_id và $industry_id khác rỗng
                $condition = array("job_id"=>$job_id,"job.industry_id"=>$industry_id);
                $result = $this->recruitment_model->getSingleRecruitment($condition);
                $this->outputData['singleRecruitment'] = $result;
                if ($result->num_rows() > 0) {
                    $this->outputData['page_title'] = $result->row()->job_name;
                    $this->outputData['meta_keywords'] = $result->row()->job_name;
                    $this->outputData['meta_description'] = $result->row()->job_name;
                }
            }else{
                // nếu $job_id và $industry_id bằng rỗng
            }

        }else{
            // nếu $job_id và $industry_id không phải là integer

        }

    	$this->load->view("recruitment/singleRecruitment",$this->outputData);
    }

    function showAllRecruitment(){
        // pagination
        $page_rows = 5;
        $page = $this->uri->segment(3,'0');
        if(isset($page)===false or empty($page)){
            $page = 1;
        }
        $limit = array($page_rows,($page - 1) * $page_rows);
        $condition = array();       

        $data = $this->recruitment_model->getAllRecruitment($condition,$limit);
        $re_num_rows =  $this->recruitment_model->getAllRecruitment($condition);      
        $this->outputData['allRecruitment'] = $data;

        // pagination continue
        $this->load->library('pagination');
        $config['base_url']     = site_url('recruitment/showAllRecruitment/');
        $config['total_rows']   = $re_num_rows->num_rows();        
        $config['per_page'] = $page_rows; 
        $config['cur_page'] = $page;
        $config['next_link']    = 'Next';
        $config['prev_link']    = 'Prev';
        $this->pagination->initialize($config);     
        $this->outputData['pagination']   = $this->pagination->create_links(false,'recruitment');
        $this->load->view("recruitment/allRecruitment",$this->outputData);
    }

    function getJobRelated($job_id = ""){
        if(filter_var($job_id, FILTER_VALIDATE_INT, array('min_range' =>1))){
            if($job_id != ""){
                $condition = array("job_id"=>$job_id);
                $result = $this->recruitment_model->getJobRelated($condition);
                return  $result;
            }
        }
    }

}
?>